<?php
namespace app\admin\controller;

use app\common\model\BeautyTemple as BeautyTempleModel;
/**
 * 美丽寺院控制器
 * Class Beautytemplate
 * @package app\index\controller
 */
class Beautytemplate extends Base
{
    /**
     * [index  查看]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $this->getPageAndSize($param);
        $model = new BeautyTempleModel();
        $map = [];
        $user = $this->user;
        try{
            if(!empty($param['start']) || !empty($param['end'])){
                $map['create_time'] = ['between',[strtotime($param['start']),strtotime($param['end'])]];
            }
            if(!empty($param['title'])){
                $map['title'] = ['like', "%" . $param['title'] . "%"];
            }
            $map['status'] = ['neq',2];
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getlist($map,$this->from, $this->size);
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        return admin_json(1,'获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
    /**
     * [add  添加]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function add()
    {
        $param = input('param.');
        $model = new BeautyTempleModel();
        try{
            $model->addData($param);
        }catch(\Exception $e){
            return admin_json(-1, '添加失败'.$e->getMessage());
        }
        return admin_json(1, '添加成功');
    }
    /**
     * [edit  编辑]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function edit()
    {
        $param = input('param.');
        $model = new BeautyTempleModel();
        try{
            $model->editData($param);
        }catch(\Exception $e){
            return admin_json(-1, '编辑失败'.$e->getMessage());
        }
        return admin_json(1, '编辑成功');
    }
    /**
     * [del  删除]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function del()
    {
        $param = input('param.');
        $model = new BeautyTempleModel();
        try{
            $model->editData(['id'=>$param['id'],'status'=>2]);
        }catch(\Exception $e){
            return admin_json(-1, '删除失败'.$e->getMessage());
        }
        return admin_json(1, '删除成功');
    }
}